package com.thesale.thesaleuser.LoaderFactory;

import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.DefaultPropertySourceFactory;
import org.springframework.core.io.support.EncodedResource;

import java.io.IOException;

public class YmlPropertyLoaderFactory extends DefaultPropertySourceFactory {
    public YmlPropertyLoaderFactory() {
    }

    public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
        return resource == null ? super.createPropertySource(name, resource) : (PropertySource)(new YamlPropertySourceLoader()).load(resource.getResource().getFilename(), resource.getResource()).get(0);
    }
}
